Look into options['extract'] for checking the extraction type.

WebsiteAgent#extraction_type was private and uncallable, and may not
remain existent in future.

Akinori MUSHA 9 anni fa
parent
commit
70157dc687
1 ha cambiato i file con 9 aggiunte e 1 eliminazioni
  1. 9 1
      db/migrate/20140723110551_adopt_xpath_in_website_agent.rb

+ 9 - 1
db/migrate/20140723110551_adopt_xpath_in_website_agent.rb

@@ -1,7 +1,15 @@
1 1
 class AdoptXpathInWebsiteAgent < ActiveRecord::Migration
2
+  class Agent < ActiveRecord::Base
3
+    include JSONSerializedField
4
+    json_serialize :options
5
+  end
6
+
2 7
   def up
3 8
     Agent.where(type: 'Agents::WebsiteAgent').each do |agent|
4
-      next if agent.extraction_type == 'json'
9
+      extract = agent.options['extract']
10
+      next unless extract.is_a?(Hash) && extract.all? { |name, detail|
11
+        detail.key?('xpath') || detail.key?('css')
12
+      }
5 13
 
6 14
       agent.options_will_change!
7 15
       agent.options['extract'].each { |name, extraction|